using System;
using System.Collections.Generic;
using System.Text;
using Entities;
using DAL;
using Utility;

namespace BUS
{
   public class tbTraLoiBUS
    {
        public static void Insert(tbTraLoi traloi)
        {
            tbTraLoiDAL tlDAL = new tbTraLoiDAL();
            tlDAL.Insert(traloi);
        }
        public static void Update(tbTraLoi traloi)
        {
            tbTraLoiDAL tlDAl = new tbTraLoiDAL();
            tlDAl.Update(traloi);
        }
        public static void Delete(int iD)
        {
            tbTraLoiDAL tlDAl = new tbTraLoiDAL();
            tlDAl.Delete(iD);
        }
        public static tbTraLoiCollection Get(string where, int pageindex, int pagesize, string orderby, string orderdirection, out int total)
        {
            tbTraLoiDAL tlDAL = new tbTraLoiDAL();
            return tlDAL.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
        public static tbTraLoiCollection GetAll()
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbTraLoiDAL tlDAL = new tbTraLoiDAL();
            return tlDAL.Get(cri.Criter, 0, 0, tbTraLoiColumns.MaTL.ToString(), OrderDirection.ASC.ToString(), out total);
        }
        public static tbTraLoi GetByID(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, tbTraLoiColumns.MaTL.ToString(), Condition.EQUAL, iD);
            tbTraLoiDAL tlDAL = new tbTraLoiDAL();
            tbTraLoiCollection tlCollection = tlDAL.Get(cri.Criter, 0, 0, tbTraLoiColumns.MaTL.ToString(), OrderDirection.ASC.ToString(), out total);
            if (tlCollection.Count > 0)
                return tlCollection[0];
            return null;
        }
        public static tbTraLoiCollection GetLimited(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbTraLoiDAL tlDAL = new tbTraLoiDAL();
            return tlDAL.Get(cri.Criter, 1, number, tbTraLoiColumns.MaTL.ToString(), OrderDirection.DESC.ToString(), out total);
        }
        public static tbTraLoiCollection GetPromotion(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbTraLoiDAL tlDAL = new tbTraLoiDAL();
            return tlDAL.Get(cri.Criter, 1, number, tbTraLoiColumns.MaTL.ToString(), OrderDirection.DESC.ToString(), out total);
        }
    }
}
